package com.zsl.swing.redis.desktop.window.menu;

import com.zsl.swing.redis.desktop.common.Constants;
import com.zsl.swing.redis.desktop.model.FontSizeConfigEntity;
import com.zsl.swing.redis.desktop.utils.FontUtils;
import com.zsl.swing.redis.desktop.window.ZslRedisDesktopMainWindow;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;

public class ZslMenuItem extends JMenuItem {

    private static int WIDTH = 160;

    private static int HEIGHT = 30;

    private ZslMenuItem(String itemName){
        this(itemName,WIDTH);
    }

    private ZslMenuItem(String itemName, int width){
        super(itemName);

        FontSizeConfigEntity fontSizeConfig = ZslRedisDesktopMainWindow.getFontSizeConfig();
        this.setFont(FontUtils.getFont(fontSizeConfig.getFontName(), Font.PLAIN, fontSizeConfig.getMenu()));
        this.setPreferredSize(new Dimension(width,HEIGHT));

    }


    public static ZslMenuItem getInstance(String itemName, ActionListener actionListener){
        return getInstance(itemName, WIDTH, actionListener);
    }

    public static ZslMenuItem getInstance(String itemName, int width, ActionListener actionListener){
        ZslMenuItem zslMenuItem = new ZslMenuItem(itemName, width);
        zslMenuItem.addActionListener(actionListener);
        return zslMenuItem;
    }
}
